﻿/***************************字符串求左右***************************/
String.prototype.left = function (len) {
    if (isNaN(len) || len == null) { len = this.length; } else { if (parseInt(len) < 0 || parseInt(len) > this.length) { len = this.length; } } return this.substr(0, len);
}
String.prototype.right = function (len) {
    if (isNaN(len) || len == null) { len = this.length; } else { if (parseInt(len) < 0 || parseInt(len) > this.length) { len = this.length; } } return this.substring(this.length - len, this.length);
}

/***************************初始化行政区选择框***************************/

function InitXZQList(inputidxzq, jb) {
    this.m_jb = jb;
    this.inputidxzq = inputidxzq;
    this.bloadedxzq = false;
    this.isxzqin = false;
    if ($("#id_div_" + inputidxzq) != null && $("#id_div_" + inputidxzq).length > 0) {
        $("#id_div_" + inputidxzq).remove();
    }
    var html = "<div xzqid='" + inputidxzq + "' id='id_div_" + inputidxzq + "' style='font-size:10pt;z-index:30000;background:white;border:1px solid lightgray;display:none;width:280px;overflow:hidden;overflow-y:auto;position:absolute;	max-height:300px;'></div>";
    $("body").append(html);
    $("#" + inputidxzq).unbind("focus");
    $("#" + inputidxzq).unbind("blur");
    $("#" + inputidxzq).unbind("mouseenter");
    $("#" + inputidxzq).unbind("mouseleave");
    $("#" + inputidxzq).focus(funfocusxzq);
    $("#" + inputidxzq).blur(funblurxzq);
    $("#id_div_" + inputidxzq).mouseenter(funxzqmousein);
    $("#id_div_" + inputidxzq).mouseleave(funxzqmouseout);

    function funfocusxzq() {
        var left = $("#" + inputidxzq).offset().left;
        var top = $("#" + inputidxzq).offset().top;
        var height = $("#" + inputidxzq).innerHeight();
        $("#id_div_" + inputidxzq).css("left", left);
        $("#id_div_" + inputidxzq).css("top", top + height + 5);
        if (bloadedxzq == false) {
            var param = '{"condition":"1=1"}';
            GetSmJSON(DBCenterServiceUrl + "/core.asmx/GetXZQList", param, funInitXZQ);
            bloadedxzq = true;
        }
        $("#id_div_" + inputidxzq).css("display", "block");
    }
    function funblurxzq() {
        if (isxzqin) {
        }
        else {
            $("#id_div_" + inputidxzq).css("display", "none");
        }
    }
    function funxzqmousein() {
        isxzqin = true;
    }
    function funxzqmouseout() {
        isxzqin = false;
    }
    function funInitXZQ(json) {
        var obj = JSON.parse(json);
        if (obj != null && obj.length > 0) {
            if (m_jb == 3) {
                var t = obj[0].id.left(2);
                var html = '<a style="margin-top:10px;font-weight:bold;cursor:pointer"  id="' + t + '0000" >' + obj[0].name + '</a><br/><br/>';
                $("#id_div_" + inputidxzq).append(html);
                html = '<table width="99%"  style="table-layout:fixed;" id="id_ul_xzq"><tbody></tbody></table>';
                $("#id_div_" + inputidxzq).append(html);
                for (var i = 0; i < obj.length; i++) {
                    var xzq = obj[i];
                    var id = xzq.id;
                    if (xzq.id.right(2) == "00" && xzq.id.right(4) != "0000") {
                        html = "<tr style='border:0;display:table-row;vertical-align:inherit;border-color: inherit;'><td width='30%' style='padding-left:10px;border: none;word-break: break-all;vertical-align:top;cursor:pointer'><a style='font-weight:bold' id='" + xzq.id + "' pid='" + xzq.pId + "' >" + xzq.name + "</a></td><td style='border: none;padding-top:15px;padding-bottom:10px;word-wrap: break-word;' id='id_inner_xzq_" + xzq.id + "'></td></tr>";
                        $("#id_ul_xzq").append(html);
                    }
                    for (var j = 0; j < obj.length; j++) {
                        xzq = obj[j];
                        if (xzq.pId == id) {
                            html = "<a style='cursor:pointer;margin-left:10px;margin-right:10px;margin-top:10px;float:left;'  id='" + xzq.id + "' pid='" + xzq.pId + "' >" + xzq.name + "</a>";
                            $("#id_inner_xzq_" + xzq.pId).append(html);
                        }
                    }
                }
            }
            else if (m_jb == 2) {
                var t = obj[0].id.left(2);
                var html = '<a style="margin-top:10px;font-weight:bold;cursor:pointer"  id="' + t + '0000" >' + obj[0].name + '</a><br/><br/>';
                $("#id_div_" + inputidxzq).append(html);
                html = '<table width="99%"  style="table-layout:fixed;" id="id_ul_xzq"><tbody></tbody></table>';
                $("#id_div_" + inputidxzq).append(html);
                for (var i = 0; i < obj.length; i++) {
                    var xzq = obj[i];
                    var id = xzq.id;
                    if (xzq.id.right(2) == "00" && xzq.id.right(4) != "0000") {
                        html = "<tr style='border:0;display:table-row;vertical-align:inherit;border-color: inherit;'><td width='30%' style='padding-left:10px;border: none;word-break: break-all;vertical-align:top;cursor:pointer'><a style='font-weight:bold' id='" + xzq.id + "' pid='" + xzq.pId + "' >" + xzq.name + "</a></td><td style='border: none;padding-top:15px;padding-bottom:10px;word-wrap: break-word;' id='id_inner_xzq_" + xzq.id + "'></td></tr>";
                        $("#id_ul_xzq").append(html);
                    }
                }
            }
            else if (m_jb = 4) {
                html = '<table width="99%"  style="table-layout:fixed;" id="id_ul_xzq"><tbody></tbody></table>';
                $("#id_div_" + inputidxzq).append(html);
                for (var i = 0; i < obj.length; i++) {
                    var xzq = obj[i];
                    var id = xzq.id;
                    if (xzq.id.right(2) == "00" && xzq.id.right(4) != "0000") {
                        html = "<tr  style='color:blue;border:0;display:table-row;vertical-align:inherit;border-color: inherit;'><td width='20%' style='padding-left:10px;border: none;word-break: break-all;vertical-align:top;cursor:pointer'><a style='font-weight:bold' id='" + xzq.id + "' pid='" + xzq.pId + "' >" + xzq.name + "</a></td><td style='border: none;padding-top:15px;padding-bottom:10px;word-wrap: break-word;' id='id_inner_xzq_" + xzq.id + "'></td></tr>";
                        $("#id_ul_xzq").append(html);
                    }
                    for (var j = 0; j < obj.length; j++) {
                        xzq = obj[j];
                        if (xzq.pId == id) {
                            html = "<a style='color:#3d6dcc;cursor:pointer;margin-left:10px;margin-right:10px;margin-top:10px;float:left;'  id='" + xzq.id + "' pid='" + xzq.pId + "' >" + xzq.name + "</a>";
                            $("#id_inner_xzq_" + xzq.pId).append(html);
                        }
                    }
                }
            }
            else if (m_jb == 1) {
                var t = obj[0].id.left(2);
                var html = '<a style="margin-top:10px;font-weight:bold;cursor:pointer"  id="' + t + '0000" >' + obj[0].name + '</a><br/><br/>';
                $("#id_div_" + inputidxzq).append(html);
            }
        }
        $("#id_div_" + inputidxzq + " a").click(funxzqclick);
    }
    function funxzqclick() {
        $("#" + inputidxzq).val($(this).text());
        $("#" + inputidxzq).attr("xzqdm", $(this).attr("id"));
        $("#id_div_" + inputidxzq).css("display", "none");
    }
}


/***************************初始化矿产类别选择框***************************/


function InitKCLBList(inputidkclb) {
    this.inputidkclb = inputidkclb;
    this.bloadedkclb = false;
    this.iskclbin = false;
    var html = "<div kclbid='" + inputidkclb + "' id='id_div_" + inputidkclb + "' style='background:white;border:1px solid lightgray;display:none;width:300px;overflow:hidden;overflow-y:scroll;position:absolute;	max-height:300px;'></div>";
    $("body").append(html);
    $("#" + inputidkclb).focus(funfocuskclb);
    $("#" + inputidkclb).blur(funblurkclb);
    $("#id_div_" + inputidkclb).mouseenter(funkclbmousein);
    $("#id_div_" + inputidkclb).mouseleave(funkclbmouseout);

    function funfocuskclb() {
        var left = $("#" + inputidkclb).offset().left;
        var top = $("#" + inputidkclb).offset().top;
        var height = $("#" + inputidkclb).innerHeight();
        $("#id_div_" + inputidkclb).css("left", left);
        $("#id_div_" + inputidkclb).css("top", top + height + 5);
        if (bloadedkclb == false) {
            var param = '{"condition":"1=1"}';
            GetSmJSON(DBCenterServiceUrl + "/core.asmx/GetKCLB", param, funInitKCLB);
            bloadedkclb = true;
        }
        $("#id_div_" + inputidkclb).css("display", "block");
    }
    function funblurkclb() {
        if (iskclbin) {
        }
        else {
            $("#id_div_" + inputidkclb).css("display", "none");
        }
    }
    function funkclbmousein() {
        iskclbin = true;
    }
    function funkclbmouseout() {
        iskclbin = false;
    }
    function funInitKCLB(json) {
        var obj = JSON.parse(json);
        var html = "<ul style='width:100%' ></ul>";
        $("#id_div_" + inputidkclb).append(html);
        html = "<li style='width:100%'><a dm='' style='cursor:pointer'>所有</a></li>";
        $("#id_div_" + inputidkclb + " ul").append(html);
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].代码 != "70000") {
                html = "<li style='width:100%'><a dm='" + obj[i].代码 + "' style='cursor:pointer'>" + obj[i].名称 + "</a></li>";
                $("#id_div_" + inputidkclb + " ul").append(html);
            }
        }
        $("#id_div_" + inputidkclb + " ul li a").click(funkclbclick);
    }
    function funkclbclick() {
        var dm = $(this).attr("dm");
        var mc = $(this).text();
        $("#" + inputidkclb).val(mc);
        $("#" + inputidkclb).attr("dm", dm);
        $("#id_div_" + inputidkclb).css("display", "none");

        $("#" + inputidkclb).val($(this).text());
        $("#" + inputidkclb).attr("xzqdm", $(this).attr("id"));
        $("#id_div_" + inputidkclb).css("display", "none");
    }
}




/***************************初始化矿种选择框***************************/
//方法说明:该方法不分矿种和矿类，统一把代码放到kcdm属性里面
function InitKZList(inputidkz) {
    this.inputidkz = inputidkz;
    this.bloadedkz = false;
    this.iskzin = false;

    $("#" + inputidkz).attr("KCJB", "1");
    var html = "<div kzid='" + inputidkz + "' id='id_div_" + inputidkz + "' style='font-size:10pt;background:white;border:1px solid lightgray;display:none;width:300px;overflow:hidden;overflow-y:scroll;position:absolute;	max-height:300px;'></div>";
    $("body").append(html);
    $("#" + inputidkz).focus(funfocuskz);
    $("#" + inputidkz).blur(funblurkz);
    $("#id_div_" + inputidkz).mouseenter(funkzmousein);
    $("#id_div_" + inputidkz).mouseleave(funkzmouseout);

    function funfocuskz() {
        var left = $("#" + inputidkz).offset().left;
        var top = $("#" + inputidkz).offset().top;
        var height = $("#" + inputidkz).innerHeight();
        $("#id_div_" + inputidkz).css("left", left);
        $("#id_div_" + inputidkz).css("top", top + height + 5);
        if (bloadedkz == false) {
            var param = '{"condition":"1=1"}';
            GetSmJSON(DBCenterServiceUrl + "/core.asmx/GetKZList", param, funInitKZ);
            bloadedkz = true;
        }
        $("#id_div_" + inputidkz).css("display", "block");
    }
    function funblurkz() {
        if (iskzin) {
        }
        else {
            $("#id_div_" + inputidkz).css("display", "none");
        }
    }
    function funkzmousein() {
        iskzin = true;
    }
    function funkzmouseout() {
        iskzin = false;
    }
    function funInitKZ(json) {
        var obj = JSON.parse(json);
        if (obj != null && obj.length > 0) {
            var t = obj[0].id.left(2);
            var html = '<a style="margin-top:10px;font-weight:bold;cursor:pointer"  id="" >' + '清除选择' + '</a><br/><br/>';
            $("#id_div_" + inputidkz).append(html);
            html = '<table style="width:99%;table-layout:fixed;" id="id_ul_kz"><tbody></tbody></table>';
            $("#id_div_" + inputidkz).append(html);
            for (var i = 0; i < obj.length; i++) {
                var kz = obj[i];
                var id = kz.id;
                if (kz.pId == "0") {
                    html = "<tr style='white-space:normal;display:table-row;vertical-align:inherit;border-color: inherit;'><td style='white-space:normal;vertical-align:top;width:20%;cursor:pointer'><a style='color:#3d6dcc;word-break:break-all;font-weight:bold;' id='" + kz.id + "' pid='" + kz.pId + "' >" + kz.name + "</a></td><td style='' id='id_inner_kz_" + kz.id + "'></td></tr>";
                    $("#id_ul_kz").append(html);
                }
                for (var j = 0; j < obj.length; j++) {
                    kz = obj[j];
                    if (kz.pId == id) {
                        html = "<a style='color:#3d6dcc;white-space:normal;cursor:pointer;margin-left:10px;margin-right:10px;margin-top:10px;float:left;'  id='" + kz.id + "' pid='" + kz.pId + "' >" + kz.name + "</a>";
                        $("#id_inner_kz_" + kz.pId).append(html);
                    }
                }
            }
        }
        $("#id_div_" + inputidkz + " a").click(funkzclick);
    }
    function funkzclick() {
        if ($(this).attr("pid") == "0") {
            $("#" + inputidkz).attr("KCJB", "1");
        }
        else {
            $("#" + inputidkz).attr("KCJB", "2");
        }
        var val = $(this).text();
        if ($(this).text() == "清除选择") {
            val = "";
            $("#" + inputidkz).attr("KCJB", "0");
        }
        var val = $(this).text() == "清除选择" ? "" : $(this).text();
        $("#" + inputidkz).val(val);
        $("#" + inputidkz).attr("kzdm", $(this).attr("id"));
        $("#id_div_" + inputidkz).css("display", "none");
    }
}

//增加了KCFL，选择矿产分类的时候，矿种用括号括起来，查询的时候可以用in
function InitKZList2(inputidkz) {
    this.inputidkz = inputidkz;
    this.bloadedkz = false;
    this.iskzin = false;
    var html = "<div kzid='" + inputidkz + "' id='id_div_" + inputidkz + "' style='font-size:10pt;background:white;border:1px solid lightgray;display:none;width:300px;overflow:hidden;overflow-y:scroll;position:absolute;	max-height:300px;'></div>";
    $("body").append(html);
    $("#" + inputidkz).focus(funfocuskz2);
    $("#" + inputidkz).blur(funblurkz2);
    $("#id_div_" + inputidkz).mouseenter(funkzmousein2);
    $("#id_div_" + inputidkz).mouseleave(funkzmouseout2);

    function funfocuskz2() {
        var left = $("#" + inputidkz).offset().left;
        var top = $("#" + inputidkz).offset().top;
        var height = $("#" + inputidkz).innerHeight();
        $("#id_div_" + inputidkz).css("left", left);
        $("#id_div_" + inputidkz).css("top", top + height + 5);
        if (bloadedkz == false) {
            var param = '{"condition":"1=1"}';
            GetSmJSON(DBCenterServiceUrl + "/core.asmx/GetKZList", param, funInitKZ2);
            bloadedkz = true;
        }
        $("#id_div_" + inputidkz).css("display", "block");
    }
    function funblurkz2() {
        if (iskzin) {
        }
        else {
            $("#id_div_" + inputidkz).css("display", "none");
        }
    }
    function funkzmousein2() {
        iskzin = true;
    }
    function funkzmouseout2() {
        iskzin = false;
    }
    function funInitKZ2(json) {
        var obj = JSON.parse(json);
        if (obj != null && obj.length > 0) {
            var t = obj[0].id.left(2);
            var html = '<a style="margin-top:10px;font-weight:bold;cursor:pointer"  id="" >' + '清除选择' + '</a><br/><br/>';
            $("#id_div_" + inputidkz).append(html);
            html = '<table style="width:99%;table-layout:fixed;" id="id_ul_kz"><tbody></tbody></table>';
            $("#id_div_" + inputidkz).append(html);
            for (var i = 0; i < obj.length; i++) {
                var kz = obj[i];
                var id = kz.id;
                if (kz.pId == "0") {
                    html = "<tr style='white-space:normal;display:table-row;vertical-align:inherit;border-color: inherit;'><td style='white-space:normal;vertical-align:top;width:20%;cursor:pointer'><a style='color:#3d6dcc;word-break:break-all;font-weight:bold;' id='" + kz.id + "' pid='" + kz.pId + "' >" + kz.name + "</a></td><td style='' id='id_inner_kz_" + kz.id + "'></td></tr>";
                    $("#id_ul_kz").append(html);
                }
                for (var j = 0; j < obj.length; j++) {
                    kz = obj[j];
                    if (kz.pId == id) {
                        html = "<a style='color:#3d6dcc;white-space:normal;cursor:pointer;margin-left:10px;margin-right:10px;margin-top:10px;float:left;'  id='" + kz.id + "' pid='" + kz.pId + "' >" + kz.name + "</a>";
                        $("#id_inner_kz_" + kz.pId).append(html);
                    }
                }
            }
        }
        $("#id_div_" + inputidkz + " a").click(funkzclick);
    }
    function funkzclick2() {
        var val = $(this).text() == "清除选择" ? "" : $(this).text();
        $("#" + inputidkz).val(val);
        $("#" + inputidkz).attr("kzdm", $(this).attr("id"));
        $("#id_div_" + inputidkz).css("display", "none");
    }
}

/***************************初始化年度选择框***************************/
/*默认只初始化最近三年的，想初始化多个年度可通过传递参数来实现*/
function InitNDSelect(selectid, n) {
    $("#" + selectid + " option").remove();
    var myDate = new Date();
    var currND = myDate.getYear();
    try {
        var curdate = GetServerDate();
        if (curdate != null) {
            currND = curdate.substr(0, 4);
        }
    } catch (e) { }
    var ndcount = 3;
    if (n != null && n > 0) {
        ndcount = n;
    }
    for (var i = 0; i < ndcount; i++) {
        var nnd = parseInt(currND) - i;
        var html = "<option>" + nnd + "</option>";
        if (i == 0) {
            html = "<option selected='selected'>" + nnd + "</option>";
        }
        $("#" + selectid).append(html);
    }

}


/********************小数截位**************************/
function BetMathRound(value, digits) {
    var zero = "00000000000000000000";
    var str = "" + value;
    var arr = str.split(".", 2);

    if (arr.length > 1) {
        str = arr[0] + "." + arr[1].substr(0, digits) + zero.substr(0, digits - arr[1].length);
    }
    else {
        str = arr[0] + "." + zero.substr(0, digits);
    }

    //return   parseFloat(str);  
    return str;
} 